package com.kinon.tyjaccount.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.kinon.tyjaccount.R;
import com.kinon.tyjaccount.bluetoothprint.BluetoothPrintFormatUtil;
import com.kinon.tyjaccount.bluetoothprint.BluetoothService;
import com.kinon.tyjaccount.bluetoothprint.DeviceListActivity;
import com.kinon.tyjaccount.bluetoothprint.PicFromPrintUtils;
import com.kinon.tyjaccount.entity.DingdanEntity;
import com.kinon.tyjaccount.entity.GoodsInfoBean;
import com.kinon.tyjaccount.tools.HttpTools;
import com.kinon.tyjaccount.tools.NetWorkUtil;
import com.kinon.tyjaccount.tools.ToastUtil;
import com.loopj.android.http.JsonHttpResponseHandler;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;

/**
 * @author：郑谦
 * @时间：2017-3-16 下午5:38:13
 * @类名：DingdanFragment.java
 * @功能: 晚餐订单（打印）
 */
public class DayingFragment extends Fragment{

	View iscatview = null;
	private ListView pull_dingdan;
	/**没有商品*/
	private TextView tv_none;
	private int offset = 0;
	private int page = 500;
	HttpTools toolModel=null;
	String token;
	private Button btn_yijiantongzhi;
	HttpTools httpTools=null;
	/** 打印信息的集合 */
	private ArrayList<DingdanEntity> dayingslist;
	DayingAdapter dayingAdapter;

	public static final int MESSAGE_STATE_CHANGE = 1;
	public static final int MESSAGE_READ = 2;
	public static final int MESSAGE_WRITE = 3;
	public static final int MESSAGE_DEVICE_NAME = 4;
	public static final int MESSAGE_TOAST = 5;

	// Key names received from the BluetoothService Handler
	public static final String DEVICE_NAME = "device_name";
	public static final String TOAST = "toast";

	// Intent request codes
	private static final int REQUEST_CONNECT_DEVICE = 1;
	private static final int REQUEST_ENABLE_BT = 2;

	// Name of the connected device
	private String mConnectedDeviceName = null;
	// String buffer for outgoing messages
	private StringBuffer mOutStringBuffer;
	// Local Bluetooth adapter
	private BluetoothAdapter mBluetoothAdapter = null;
	// Member object for the services
	public static BluetoothService mService = null;

	BluetoothPrintFormatUtil printFormatUtil = null;

	LinkedHashMap<String, LinkedList<String>> menuMsgMap;

	LinkedList<String> gonds;
	ArrayList<GoodsInfoBean> detaillist ;

	private String orderno;
	private String order_time;
	private String book_time;
	private String fee;
	private String recmode;
	private double heji;
	private String note;
	private String address;
	private String shoushuofangshi="";
	private String total;
	private String name;
	private String phone;
	private String shuliang;
	private String totalamount;
	private String dayno;

	private Context mContext;

	ToastUtil toastUtil=new ToastUtil();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		mContext=getActivity();
		return inflater.inflate(R.layout.fragment_daying, null);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		initRes();

	}
	@Override
	public void onStart() {
		super.onStart();
//		handler.postDelayed(runnable, 10000);
		if (!mBluetoothAdapter.isEnabled()) {
			//打开蓝牙
			Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
			startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
		}
		if (mService==null) {
			mService = new BluetoothService(getActivity(), mHandler);
		}
	}


	private void initRes() {
		SharedPreferences sp = getActivity().getSharedPreferences("spReg",
				Context.MODE_PRIVATE);
		token = sp.getString("data", "");
		btn_yijiantongzhi = (Button) getView().findViewById(R.id.btn_yijiantongzhi);
		pull_dingdan = (ListView) getView().findViewById(
				R.id.pull_dingdan);

//		pull_dingdan.setMode(Mode.BOTH);
//		pull_dingdan.setOnRefreshListener(onrefresh);
		//		pull_twosort.setOnItemClickListener(itemclicke);
		tv_none = (TextView)getView().findViewById(R.id.tv_none);

		getDingdaninfo();

		btn_yijiantongzhi.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
//				Yijiantongzhi();
				tongzhidialog();
			}
		});
		mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

		// If the adapter is null, then Bluetooth is not supported
		if (mBluetoothAdapter == null) {
			Toast.makeText(getActivity(), "您的设备不支持蓝牙", Toast.LENGTH_SHORT).show();
//			finish();
			return;
		}
	}

	private void Yijiantongzhi() {
		if (httpTools == null) {
			httpTools = new HttpTools(getActivity());
		}
		httpTools.noticeAllUsers(token,new JsonHttpResponseHandler() {

			@Override
			public void onSuccess(int statusCode, Header[] headers,
								  JSONObject response) {
				super.onSuccess(statusCode, headers, response);
				try {
					boolean code = response.getBoolean("code");
					String msg = response.getString("msg");
					if (code == true) {
    						Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
						getDingdaninfo();
					} else {
						Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(Throwable e, JSONObject errorResponse) {
				super.onFailure(e, errorResponse);
				Toast.makeText(getActivity(),
						"网络请求失败", Toast.LENGTH_SHORT).show();
			}

		});
	}

	/**获取订单列表*/
	private void getDingdaninfo() {
		if(NetWorkUtil.isNetwork(getActivity())==false)
		{
			toastUtil.Short(getActivity(),"  "+"当前网络不可用")
					.setToastBackground(Color.WHITE,0).show();
			return;
		}
		dayingslist = new ArrayList<DingdanEntity>();

		toolModel = new HttpTools(getActivity());
		toolModel.getOrders(token, page + "", offset + "","0",
				new JsonDingdan());
	}

	private class JsonDingdan extends JsonHttpResponseHandler {

		@Override
		public void onSuccess(int statusCode, Header[] headers,
							  JSONObject response) {
			super.onSuccess(statusCode, headers, response);

			try {
//				Log.i("info","订单列表----"+response.toString());
				boolean code = response.getBoolean("code");
				String msg = response.getString("msg");
				if (code==true) {
					JSONArray data = response.getJSONArray("data");
					for (int i = 0; i < data.length(); i++) {
						JSONObject object = data.getJSONObject(i);
						String id=object.getString("id");
						String name=object.getString("name");
						String orderno=object.getString("dayno");
						String total=object.getString("total");
						String print=object.getString("print");
						String notice=object.getString("notice");
						String refund=object.getString("refund");
						String order_time=object.getString("order_time");
						dayingslist.add(new DingdanEntity(id, orderno, name, total, order_time,refund,print,notice));
					}
					if (dayingslist.size()==0) {
						tv_none.setVisibility(View.VISIBLE);
					}else {
						tv_none.setVisibility(View.GONE);
					}
					dayingAdapter=new DayingAdapter(getActivity(), dayingslist);
					pull_dingdan.setAdapter(dayingAdapter);
					pull_dingdan.setDivider(null);
				}else {
					Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		@Override
		public void onFailure(Throwable e, JSONObject errorResponse) {
			super.onFailure(e, errorResponse);
			Toast.makeText(getActivity(),
					"网络请求失败", Toast.LENGTH_SHORT).show();
		}

	}

	/**
	 * 打印
	 * @param message
	 */
	private void sendMessage(String message) {
		if (message.length() > 0) {
			// Get the message bytes and tell the BluetoothService to write
			byte[] send;
			try {
				send = message.getBytes("GB2312");
			} catch (UnsupportedEncodingException e) {
				send = message.getBytes();
			}

			mService.write(send);
		}
	}


	private void sendMessage(Bitmap bitmap) {
		// Check that we're actually connected before trying anything
		if (mService.getState() != BluetoothService.STATE_CONNECTED) {
			Toast.makeText(getActivity(), "蓝牙没有连接", Toast.LENGTH_SHORT).show();
			return;
		}
		// 发送打印图片前导指令
		byte[] start = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B,
				0x40, 0x1B, 0x33, 0x00 };
		mService.write(start);

		/**获取打印图片的数据**/
//		byte[] send = getReadBitMapBytes(bitmap);

		mService.printCenter();
		byte[] draw2PxPoint = PicFromPrintUtils.draw2PxPoint(bitmap);

		mService.write(draw2PxPoint);
		// 发送结束指令
		byte[] end = { 0x1d, 0x4c, 0x1f, 0x00 };
		mService.write(end);
	}

	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
			case REQUEST_CONNECT_DEVICE:
				// When DeviceListActivity returns with a device to connect
				if (resultCode == Activity.RESULT_OK) {
					// Get the device MAC address
					String address = data.getExtras()
							.getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
					// Get the BLuetoothDevice object
					BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
					// Attempt to connect to the device
					mService.connect(device);
				}
				break;
			case REQUEST_ENABLE_BT:
				// When the request to enable Bluetooth returns
				if (resultCode == Activity.RESULT_OK) {
//                setupChat();
					Toast.makeText(getActivity(), "蓝牙已打开", Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(getActivity(), "蓝牙没有打开", Toast.LENGTH_SHORT).show();
//                finish();
				}
		}
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.scan:
				// Launch the DeviceListActivity to see devices and do scan
				Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class);
				startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
				return true;
			case R.id.disconnect:
				// disconnect
				mService.stop();
				return true;
		}
		return false;
	}


	// The Handler that gets information back from the BluetoothService
	private final Handler mHandler = new Handler() {
		@SuppressLint("HandlerLeak")
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
				case MESSAGE_STATE_CHANGE:
					switch (msg.arg1) {
						case BluetoothService.STATE_CONNECTED:
//                	print_connect_btn.setText("已连接:");
//                	print_connect_btn.append(mConnectedDeviceName);
							break;
						case BluetoothService.STATE_CONNECTING:
//                	print_connect_btn.setText("正在连接...");
//							Toast.makeText(getActivity(), "正在连接...", Toast.LENGTH_LONG).show();
							break;
						case BluetoothService.STATE_LISTEN:
						case BluetoothService.STATE_NONE:
//                	print_connect_btn.setText("无连接");
							break;
					}
					break;
				case MESSAGE_WRITE:
					break;
				case MESSAGE_READ:
					break;
				case MESSAGE_DEVICE_NAME:
					// save the connected device's name
					mConnectedDeviceName = msg.getData().getString(DEVICE_NAME);
					if (getActivity()==null){
//						Log.e("zq","error-------");
					}
//					Log.e("zq","s-------"+mContext.toString());
					Toast.makeText(mContext, "连接至"
							+ mConnectedDeviceName, Toast.LENGTH_SHORT).show();
					break;
				case MESSAGE_TOAST:
					Toast.makeText(getActivity(), msg.getData().getString(TOAST),
							Toast.LENGTH_SHORT).show();
					break;
			}
		}
	};
	/**打印内容*/
	private void print() {
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(printFormatUtil.printTitle("                 智慧食堂")+"\n");
		sendMessage(printFormatUtil.printTitle("************************************************")+ "\n");
//		printFormatUtil.printTitle("****************");
		sendMessage("名称" + "             "+"数量" + "              "+"价格"+" \n");
		mService.printSize(2);
		menuMsgMap.put("", gonds);
		sendMessage(printFormatUtil.printMenuMSG(menuMsgMap));
		SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String date = sDateFormat.format(new java.util.Date());
		mService.print(3);
		sendMessage("数量：" + totalamount+"份"+"   ");
		sendMessage("总价：" + total +"元"+ " \n");
//		sendMessage("备注：" + note+ " \n");
//		sendMessage("日期：" +date+ "\n");
		sendMessage("订单编号："+orderno+" \n");
//		sendMessage("下单时间："+order_time+" \n");
		sendMessage("取餐时间："+book_time+" \n");
		sendMessage("姓名："+name+" \n");
		sendMessage("联系电话："+phone+" \n");
//		ESCUtil.boldOn();

//		printFormatUtil.BOLD;
		mService.printSize(2);
		sendMessage("取餐编号："+dayno+" \n");
		mService.print(3);
//		printFormatUtil.BOLD_CANCEL;
//		ESCUtil.boldOff();
		sendMessage(printFormatUtil.printTitle("***********************************************")+"\n");
		sendMessage(printFormatUtil.printTitle("             请妥善保管好购物凭证"+"\n"));
		sendMessage(printFormatUtil.printTitle("                 谢谢惠顾！")+ "\n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
		sendMessage(" \n");
	}

	/**打印适配器*/
	public class DayingAdapter extends BaseAdapter{
		Context context;
		ArrayList<DingdanEntity> dingdanList;
		HttpTools httpTools=null;
		View iscatview = null;

		public DayingAdapter(Context context, ArrayList<DingdanEntity> dingdanList) {
			super();
			this.context = context;
			this.dingdanList = dingdanList;
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return dingdanList.size();
		}

		@Override
		public Object getItem(int position) {
			return dingdanList.get(position);
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View view, ViewGroup parent) {
			final ViewHandle handle;
			if(view==null){
				handle=new ViewHandle();
				view=LayoutInflater.from(context).inflate(R.layout.item_daying, null);
				handle.tv_bianhao=(TextView)view.findViewById(R.id.tv_order);
				handle.tv_name=(TextView)view.findViewById(R.id.tv_name);
				handle.tv_jine=(TextView)view.findViewById(R.id.tv_jine);
				handle.tv_shijian=(TextView)view.findViewById(R.id.tv_time);
				handle.btn_tuikuan=(Button)view.findViewById(R.id.btn_tuikuan);
				handle.btn_tongzhi=(Button)view.findViewById(R.id.btn_tongzhi);
				view.setTag(handle);
			}else {
				handle = (ViewHandle) view.getTag();
			}

			handle.tv_bianhao.setText(dingdanList.get(position).getOrderno());
			handle.tv_name.setText(dingdanList.get(position).getName());
			handle.tv_jine.setText("￥"+dingdanList.get(position).getTotal());
			handle.tv_shijian.setText(dingdanList.get(position).getTime());

			if (dingdanList.get(position).getPrint().equals("1")) {
				handle.btn_tuikuan.setText("已打印");
//				dayingdialog(position);
			}else {
				handle.btn_tuikuan.setText("打印");
//				Daying(position);
			}
			if (dingdanList.get(position).getNotice().equals("1")) {
				handle.btn_tongzhi.setText("已通知");
				handle.btn_tongzhi.setEnabled(false);
//				dayingdialog(position);
			}else {
				handle.btn_tongzhi.setEnabled(true);
				handle.btn_tongzhi.setText("通知");
//				Daying(position);
			}
			handle.btn_tuikuan.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					if (mService.getState() != BluetoothService.STATE_CONNECTED) {
						Toast.makeText(getActivity(), "蓝牙没有连接", Toast.LENGTH_SHORT).show();
//    					return;
//						Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class);
//						startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
						Printdialog();
//						return;
					}else {
						if (dingdanList.get(position).getPrint().equals("1")) {
//    						handle.btn_tuikuan.setText("已打印");
							dayingdialog(position);
						}else {
//							handle.btn_tuikuan.setText("打印");
							Daying(position,handle.btn_tuikuan);
						}

					}

				}
			});
			handle.btn_tongzhi.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Tongzhi(position,handle.btn_tongzhi);
				}
			});

			return view;
		}
		class ViewHandle {
			/**订单编号*/
			TextView tv_bianhao;
			/**姓名*/
			TextView tv_name;
			/**价格*/
			TextView tv_jine;
			/**时间*/
			TextView tv_shijian;
			/**打印*/
			Button btn_tuikuan;
			/**通知*/
			Button btn_tongzhi;
		}
		/**通知*/
		private void Tongzhi(final int index, final Button btn_tongzhi) {
//    		SharedPreferences sp=context.getSharedPreferences("spReg", Context.MODE_PRIVATE);
//    		String token = sp.getString("data", "");

			if (httpTools == null) {
				httpTools = new HttpTools(context);
			}
			httpTools.noticeUser(token, dingdanList.get(index).getId(),new JsonHttpResponseHandler() {

				@Override
				public void onSuccess(int statusCode, Header[] headers,
									  JSONObject response) {
					super.onSuccess(statusCode, headers, response);
					try {
						boolean code = response.getBoolean("code");
						String msg = response.getString("msg");
						if (code == true) {
							//						String data=response.getString("data");
    						Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
							btn_tongzhi.setText("已通知");
							btn_tongzhi.setEnabled(false);
							dingdanList.get(index).setNotice("1");
						} else {
							Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
							btn_tongzhi.setEnabled(true);
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}

			});
		}

		/**是否打印弹窗*/
		private void Printdialog() {

			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

			iscatview = LayoutInflater.from(context).inflate(
					R.layout.dialog_pay, null);
			TextView tital = (TextView) iscatview.findViewById(R.id.tital);
			TextView tv_no = (TextView) iscatview.findViewById(R.id.tv_no);
			TextView tv_yes = (TextView) iscatview.findViewById(R.id.tv_yes);
			tital.setText("蓝牙未连接，是否连接打印机?");
			dialog.setContentView(iscatview);
			dialog.show();
			tv_no.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
				}
			});
			tv_yes.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
//    				Tuikuan(index2);
//					Dingdandetial(index2);
					Intent serverIntent = new Intent(getActivity(), DeviceListActivity.class);
					startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
					dialog.dismiss();
				}
			});
		}


		/**打印弹窗*/
		private void dayingdialog(final int index2) {

			final Dialog dialog = new Dialog(context);
			dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

			iscatview = LayoutInflater.from(context).inflate(
					R.layout.dialog_pay, null);
			TextView tital = (TextView) iscatview.findViewById(R.id.tital);
			TextView tv_no = (TextView) iscatview.findViewById(R.id.tv_no);
			TextView tv_yes = (TextView) iscatview.findViewById(R.id.tv_yes);
			tital.setText("是否重复打印?");
			dialog.setContentView(iscatview);
			dialog.show();
			tv_no.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					dialog.dismiss();
				}
			});
			tv_yes.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
//    				Tuikuan(index2);
					Dingdandetial(index2);
					dialog.dismiss();
				}
			});
		}
		private void Daying(final int index, final Button btn_daying) {

			if (httpTools == null) {
				httpTools = new HttpTools(context);
			}
			httpTools.printOrder(token, dingdanList.get(index).getId(),new JsonHttpResponseHandler() {

				@Override
				public void onSuccess(int statusCode, Header[] headers,
									  JSONObject response) {
					super.onSuccess(statusCode, headers, response);
					try {
						boolean code = response.getBoolean("code");
						String msg = response.getString("msg");
						if (code == true) {
							Dingdandetial(index);
							btn_daying.setText("已打印");
							dingdanList.get(index).setPrint("1");
						} else {
							Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
						}
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			});
		}
		/**订单详情*/
		private void Dingdandetial(final int index) {
			detaillist = new ArrayList<GoodsInfoBean>();
			menuMsgMap = new LinkedHashMap<String, LinkedList<String>>();
			gonds=new LinkedList<String>();
			shuliang="";
//    		SharedPreferences sp = getActivity().getSharedPreferences("spReg",
//    				Context.MODE_PRIVATE);
//    		token = sp.getString("token", "");
			if (httpTools == null) {
				httpTools = new HttpTools(getActivity());
			}
			httpTools.getDetail(token,"","", dingdanList.get(index).getId(), new JsonOrderDetail());
		}

		private class JsonOrderDetail extends JsonHttpResponseHandler {
			@Override
			public void onSuccess(int statusCode, Header[] headers,
								  JSONObject response) {
				super.onSuccess(statusCode, headers, response);
				try {
					boolean code = response.getBoolean("code");
					if (code == true) {
						JSONObject object = response.getJSONObject("data");
						JSONArray array = object.getJSONArray("details");
						dayno = object.getString("dayno");
						orderno = object.getString("orderno");
						order_time = object.getString("order_time");
						book_time = object.getString("book_time");
//    					note = object.getString("note");
						total = object.getString("total");
						name = object.getString("name");
						phone = object.getString("username");
						totalamount = object.getString("totalamount");
						for (int i = 0; i < array.length(); i++) {
							JSONObject object2 = array.getJSONObject(i);
							String id = object2.getString("id");
							String name = object2.getString("name");
							String amount = object2.getString("amount");
							String price = object2.getString("price");
							String content = object2.getString("content");
							String total = object2.getString("total");
//    						shuliang +=Integer.parseInt(amount);
							double jiage = Integer.parseInt(amount)*Double.parseDouble(price);
							detaillist.add(new GoodsInfoBean(name, amount, price, content,""));
							gonds.add(" \n"+name);
							gonds.add("*"+amount);
							gonds.add(""+total);
//    						gonds.add(content+" - ");
						}
						print();
//						getDingdaninfo();
					} else {
						String msg = response.getString("msg");
						Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(Throwable e, JSONObject errorResponse) {
				super.onFailure(e, errorResponse);
				Toast.makeText(getActivity(),
						"网络请求失败", Toast.LENGTH_SHORT).show();
			}
		}
	}


	/**一键通知弹窗*/
	private void tongzhidialog() {

		final Dialog dialog = new Dialog(getActivity());
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

		iscatview = LayoutInflater.from(getActivity()).inflate(
				R.layout.dialog_pay, null);
		TextView tital = (TextView) iscatview.findViewById(R.id.tital);
		TextView tv_no = (TextView) iscatview.findViewById(R.id.tv_no);
		TextView tv_yes = (TextView) iscatview.findViewById(R.id.tv_yes);
		tital.setText("是否通知所有用户?");
		dialog.setContentView(iscatview);
		dialog.show();
		tv_no.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		tv_yes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Yijiantongzhi();
				dialog.dismiss();
			}
		});
	}
}
